package com.aaa.mbs.service.impl;


import com.aaa.common.constants.ExceptionConstant;
import com.aaa.common.constants.ReturnStatus;
import com.aaa.common.util.CustomException;
import com.aaa.common.util.Result;
import com.aaa.mbs.dao.IntegrationHistoryDao;
import com.aaa.mbs.entity.IntegrationHistory;
import com.aaa.mbs.entity.MemberLevel;
import com.aaa.mbs.service.IntegrationHistoryService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * (IntegrationHistory)表服务实现类
 *
 * @author makejava
 * @since 2020-12-05 10:04:50
 */
@Service("integrationHistoryService")
public class IntegrationHistoryServiceImpl implements IntegrationHistoryService {
    @Resource
    private IntegrationHistoryDao integrationHistoryDao;

    /**
     * 通过ID查询单条数据
     *
     * @param id 主键
     * @return 实例对象
     */
    @Override
    public IntegrationHistory queryById(Long id) {
        return this.integrationHistoryDao.queryById(id);
    }

    @Override
    public Result queryAllByParam(int pageNo, int pageSize, IntegrationHistory integrationHistory) {
        if (pageNo == 0 || pageSize == 0) {
            throw new CustomException(ExceptionConstant.INVALID_ARGUMENT.getErrorCode(),
                    ExceptionConstant.INVALID_ARGUMENT.getErrorMessage());
        }
        PageHelper.startPage(pageNo, pageSize);
        System.out.println(integrationHistory);
        PageInfo<IntegrationHistory> pageInfo = new PageInfo<>(integrationHistoryDao.queryAll(integrationHistory));
        return new Result(ReturnStatus.SUCCESS.getReturnCode(), ReturnStatus.SUCCESS.getReturnMsg(), pageInfo);

    }

    /**
     * 通过实体作为筛选条件查询
     *
     *
     * @param integrationHistory 实例对象
     * @return 对象列表
     */
    @Override
    public List<IntegrationHistory> queryAll(IntegrationHistory integrationHistory) {
        return  this.integrationHistoryDao.queryAll(integrationHistory);
    }

    /**
     * 查询多条数据
     *
     * @param offset 查询起始位置
     * @param limit  查询条数
     * @return 对象列表
     */
    @Override
    public List<IntegrationHistory> queryAllByLimit(int offset, int limit) {
        return this.integrationHistoryDao.queryAllByLimit(offset, limit);
    }

    /**
     * 新增数据
     *
     * @param integrationHistory 实例对象
     * @return 实例对象
     */
    @Override
    public IntegrationHistory insert(IntegrationHistory integrationHistory) {
        this.integrationHistoryDao.insert(integrationHistory);

        return integrationHistory;
    }

    /**
     * 修改数据
     *
     * @param integrationHistory 实例对象
     * @return 实例对象
     */
    @Override
    public IntegrationHistory update(IntegrationHistory integrationHistory) {
        this.integrationHistoryDao.update(integrationHistory);
        return this.queryById(integrationHistory.getId());
    }

    /**
     * 通过主键删除数据
     *
     * @param id 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Long id) {
        return this.integrationHistoryDao.deleteById(id) > 0;
    }
}